/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cjava.system.dao.hibernate;

import java.util.ArrayList;
import java.util.List;
import org.cjava.system.dao.interfac.IPersonDao;
import org.cjava.system.dao.util.GenericEntityDao;
import org.cjava.system.model.Person;
import org.cjava.system.model.PersonProfile;
import org.hibernate.Hibernate;

/**
 *
 * @author max
 */
public class PersonDao extends GenericEntityDao<Person, Long> implements IPersonDao {

    @Override
    public List listHQL(String hql, int lazyChargeOption, Object object) throws Exception {
        List list = new ArrayList<>();
        if (lazyChargeOption == 1) {
            list = getSessionFactory().getCurrentSession()
                    .createQuery(hql)
                    .list();
            List<Person> listPer = (List<Person>)list;
            for (Person pers : listPer) {
                for (PersonProfile personPro : pers.getPersonProfileList()) {
                    Hibernate.initialize(personPro);                    
                }
            }
        }
        return list;
    }

}
